<!DOCTYPE html>
<html lang="zh-cn">
<head>
{include file="public/header" /}
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head"><strong class="icon-menu"> 栏目列表</strong></div>
  <div class="padding border-bottom">
    <a href="javascript:;" type="button" class="button border-yellow" onclick="openifram('添加栏目','60%','400px','{:url('cate/add')}')"><span class="icon-tianjia"></span> 添加栏目</a>
    <a href="javascript:void(0)" class="button border-blue icon-paixu1" onclick="sorts()"> 排序</a>
    <button type="button"  class="button border-green" id="checkall"><span class="icon-xuanze"></span> 全选</button>
    <button type="submit" class="button border-red" onclick="delall()" id="checkdel"><span class="icon-shanchu"></span> 批量删除</button>
    <button type="submit" class="button border-red" onclick="Emptied()" id="checkdel"><span class="icon-ziyuan"></span> 清空</button>
  </div>
  <table class="table table-hover text-center">
    <tr>
      <th width="5%">ID</th>
      <th width="10%">排序</th>
      <th width="15%">一级分类</th>
      <th width="10%">栏目属性</th>
      <th width="10%">操作</th>
    </tr>
    {volist name="cate" id="vo"}
    <tr>
      <td><input type="checkbox" name="id[]" value="{$vo.id}">{$vo.id}</td>
      <td><input type="text" name="{$vo.id}" value="{$vo.sort}" title="{$vo.id}" id="sorts" style="width: 30px;"></td>
      <td>{$vo.name_display}</td>
      <td>{$vo['sf']|cate_types}</td>
      <td>
        <div class="button-group"> 
          <a class="button border-main" href="javascript:;" onclick="openifram('修改栏目','60%','400px','{:url('cate/edit',['id'=>$vo.id])}')"><span class="icon-xiugai"></span> 修改</a> 
          <a class="button border-red" href="javascript:void(0)" onclick="system_category_del(this,{$vo.id})"><span class="icon-shanchu"></span> 删除</a>
      </div></td>
    </tr>
    {/volist}
  </table>
</div>
<script type="text/javascript">
// 排序
function sorts(){
  var array=[];
  $("input[type='text']").each(function(){
    array.push({
      'id':$(this).prop("name"),
      'sort' : $(this).val(),
    })
  });
  console.log(array);
  $.ajax({
    type:"POSt",
    url:"{:url('cate/sorts')}",
    data:{
      array,
      // 'id':sorids,
    },
    success:function(data){
      var data=eval("("+data+")");
      if (data.status) {
        parent.layer.msg('排序成功~！',{icon:1,time:1000,},function(){parent.location.reload();});
      }else{
        parent.layer.msg('排序失败~！',{icon:2,time:1000,},function(){parent.location.reload();});
      }
    }
  });
}

// 全选
jQuery(function($){
  //全选 
  $("#checkall").click(function(){ 
      $("input[name='id[]']").attr("checked","true"); 
      // $("input[name='checkbox']:checkbox:checked").each(function(){ 
      //     aa.push($(this).val());
      // })
      // console.log(aa);
      // aa= new Array();
  })
})
function delall(){
  layer.confirm('是否全部删除',function(){
    var ids= new Array(); 
    $("input[name='id[]']:checkbox:checked").each(function(){ 
      ids.push($(this).val());
    });
    var idj=ids.join(",")
    // alert(idj);
    $.ajax({
      type:"GET",
      url:"{:url('cate/delall')}",
      data:{
        'id':idj,
      },
      success:function(data){
        var data=eval("("+data+")");
        if (data.status) {
          parent.layer.msg('删除成功~！',{icon:1,time:1000,},function(){parent.location.reload();});
        }else{
          parent.layer.msg('删除失败~！',{icon:2,time:1000,},function(){parent.location.reload();});
        }
      }
    })
  });
}

// 单个删除
function system_category_del(obj, id) {

  layer.confirm('确认要删除吗？', function (index) {

    $.ajax({
        type: "POST",
        url: "{:url('cate/del')}",
        data: {
        'id':id,
        },
        dataType: "json",
        success: function(data){
          var data=eval("("+data+")");

        if (data.status){

          parent.layer.msg('删除成功~！',{icon:1,time:1000,},function(){parent.location.reload();});
        
        }
        else{
        parent.layer.msg('删除失败~！',{icon:2,time:1000,},function(){parent.location.reload();});
        }
        }
      });
    });
}
// 弹窗
function openifram(title,width,height,url){
    layer.open({
      type: 2,
      title: title,
      fixed:false,
      area: [width, height],
      shade: [0.2, '#393D49'],
      maxmin: true,
      content: url,
  });
}
// 当前数据表清空炒作
function Emptied(){
  layer.confirm('确定要清空吗？', {
    time: 0 ,//不自动关闭
    btn: ['必须啊', '不必了'],
    yes: function(index){
      var id=1;
      $.ajax({
        type: "POST",
        url: "{:url('cate/emptied')}",
        data: {
        'id':id,
        },
        dataType: "json",
        success: function(data){
          var data=eval("("+data+")");

        if (data.status == 1){

          parent.layer.msg('当前表清除成功！！！！！',{icon:1,time:1000,},function(){parent.location.reload();});
        
        }
        else{
        parent.layer.msg('当前表清除失败！！！！！~！',{icon:2,time:1000,},function(){parent.location.reload();});
        }
        }
      });
    }
  });
}
</script>
</body>
</html>